<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        #app {
            border: 2px solid black;
            padding: 10px;
            margin-bottom: 400px;
        }

        .child {
            margin: 20px;
            padding: 10px;
            background-color: #cccccc;
        }
    </style>
</head>

<body>
    <div id="app">
        <h3>父组件范围</h3>
        <p>skills:{{skills}}</p>
        <div>
            html:<input type="checkbox" value="html" v-model="skills">
            javaScript:<input type="checkbox" value="javaScript" v-model="skills">
            Vue:<input type="checkbox" value="Vue" v-model="skills">
        </div>
        <child-one :skills="skills" @update-skills="setSkills"></child-one>
    </div>
    <template id="ChildOne">
        <div class="child">
            <h3>子组件范围</h3>
            <p>skills:{{skills}}</p>
            <div>
                html:<input type="checkbox" value="html" v-model="getSkills">
                javaScript:<input type="checkbox" value="javaScript" v-model="getSkills">
                Vue:<input type="checkbox" value="Vue" v-model="getSkills">
            </div>
            <hr>
            <div>
                html:<input type="checkbox" value="html" v-model="getCheckData">
                javaScript:<input type="checkbox" value="javaScript" v-model="getCheckData">
                Vue:<input type="checkbox" value="Vue" v-model="getCheckData">
            </div>
        </div>
    </template>
</body>
<script>
    Vue.component("ChildOne", {
        template: "#ChildOne",
        data(){
            return {
                checkData:[]
            }
        },
        props:["skills"],
        computed: {
            getCheckData:{
                get(){
                    return this.checkData;
                },
                set(nv){
                    console.log(nv);
                    this.checkData=nv;
                }
            },
            getSkills:{
                get(){
                    return this.skills;
                },
                set(nv){
                    // console.log(nv);
                    // this.skills=nv;
                    this.$emit("update-skills",nv);
                }
            }
        },
    });

    new Vue({
        el: "#app",
        data: {
            skills:[]
        },
        methods: {
            setSkills(nv){
                this.skills = nv;
            }
        },
    });
</script>

</html>